<?php

namespace App\Http\Controllers;

use Illuminate\Http\Request;

use App\Http\Requests;
use App\Http\Controllers\Controller;
use DB;
class UserController extends Controller
{
    /**
     *
     */
    public function find(Request $request)
    {
        // //搜索的关键字
        $keywords = $request->input('keywords');
        //第一种方法
           //如果参数为空s
        if(empty($keywords)) {
             $users = DB::table('users')
            ->paginate(3);
        }else{//如果不为空
             $users = DB::table('users')
            ->where('name','like','%'.$keywords.'%')
            ->get();
        }
        return view('user.list',['users'=>$users,'data'=>$request->all()]);
    }
}
